#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
作者：消逝
QQ交流群：540681925
"""

import sys
from frmmain_ui import Ui_frmMain
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class frmMain(QMainWindow):
    def __init__(self, parent=None):
        super(frmMain, self).__init__(parent)
        self.ui = Ui_frmMain()
        self.ui.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.ui.closeToolButton.clicked.connect(self.on_closeToolButton_clicked)
        self.ui.minToolButton.clicked.connect(self.on_minToolButton_clicked)
        self.ui.killToolButton.clicked.connect(self.on_killToolButton_clicked)
        self.ui.checkToolButton_2.clicked.connect(self.on_checkToolButton_2_clicked)
        self.ui.fixToolButton.clicked.connect(self.on_fixToolButton_clicked)
        self.ui.rabToolButton.clicked.connect(self.on_rabToolButton_clicked)
        self.ui.opToolButton.clicked.connect(self.on_opToolButton_clicked)
        self.ui.exToolButton.clicked.connect(self.on_exToolButton_clicked)
        self.ui.mzToolButton.clicked.connect(self.on_mzToolButton_clicked)
        self.ui.gjToolButton.clicked.connect(self.on_gjToolButton_clicked)

    def mousePressEvent(self,event):
        if ( event.button() == Qt.LeftButton ):
            self.startPos = event.globalPos() - self.frameGeometry().topLeft()
        elif ( event.button() == Qt.MiddleButton):
            self.closeWindow()
        elif(  event.button() == Qt.RightButton ):
            self.shakeWindow()

    def mouseMoveEvent(self,event):
        if ( event.buttons() == Qt.LeftButton ):
            self.endPos = event.globalPos() - self.startPos
            self.move(self.endPos)

    def on_closeToolButton_clicked(self):
        self.closeWindow()

    def on_minToolButton_clicked(self):
        self.showMinimized()

    def shakeWindow(self):
        animation = QPropertyAnimation(self,"geometry")
        animation.setDuration(500)
        animation.setKeyValueAt(0,QRect(QPoint(self.frameGeometry().x()-3,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.1,QRect(QPoint(self.frameGeometry().x()+6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.2,QRect(QPoint(self.frameGeometry().x()-6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.3,QRect(QPoint(self.frameGeometry().x()+6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.4,QRect(QPoint(self.frameGeometry().x()-6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.5,QRect(QPoint(self.frameGeometry().x()+6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.6,QRect(QPoint(self.frameGeometry().x()-6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.7,QRect(QPoint(self.frameGeometry().x()+6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.8,QRect(QPoint(self.frameGeometry().x()-6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(0.9,QRect(QPoint(self.frameGeometry().x()+6,self.frameGeometry().y()),self.size()))
        animation.setKeyValueAt(1,QRect(QPoint(self.frameGeometry().x()-3,self.frameGeometry().y()),self.size()))
        animation.start()

    def setStackCurrentPage(self,index):
        widget =QWidget()
        widget = self.ui.stackedWidget.widget(index)
        self.ui.stackedWidget.setCurrentWidget(widget)

    def closeWindow(self):
        sys.exit(app.exec_())

    def on_killToolButton_clicked(self):
        self.setStackCurrentPage(1)

    def on_checkToolButton_2_clicked(self):
        self.setStackCurrentPage(0)

    def on_fixToolButton_clicked(self):
        self.setStackCurrentPage(2)

    def on_rabToolButton_clicked(self):
        self.setStackCurrentPage(3)

    def on_opToolButton_clicked(self):
        self.setStackCurrentPage(4)

    def on_exToolButton_clicked(self):
        self.setStackCurrentPage(5)

    def on_mzToolButton_clicked(self):
        self.setStackCurrentPage(6)

    def on_gjToolButton_clicked(self):
        self.setStackCurrentPage(7)
        
if __name__ == "__main__":
    app = QApplication(sys.argv[1:])
    window = frmMain()
    window.show()
    sys.exit(app.exec_())
